//app.js
App({
  //小程序启动的时候就会调用它
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

  },
  //通过调用 wx.login 和 wx.getUserInfo 两个微信平台的函数获取当前用户登录信息，并传会给回调函数 cb：
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo&&this.globalData.sessionid) {
      typeof cb == "function" && cb(this.globalData.userInfo,this.globalData.sessionid)
    } else {
      //调用登录接口
      wx.login({
        success: function (res) {
          wx.setStorageSync('code', res.code)
          console.log("--------code---", wx.getStorageSync('code'))
          wx.getUserInfo({
            success: function (res) {
              // success
              that.globalData.userInfo = res.userInfo
              that.globalData.sessionid= wx.getStorageSync('sessionid')
               console.log("---------sessionid------------2", wx.getStorageSync('sessionid'))
              typeof cb == "function" && cb(that.globalData.userInfo,that.globalData.sessionid)
              console.log("----res----", res)
              console.log("---------sessionid------------3", wx.getStorageSync('sessionid'))
            },
          })
        },
      })
    }
  },
 
  globalData: {
    userInfo: null,
    sessionid: wx.getStorageSync('sessionid'),
    devicedata:wx.getStorageSync('devicedata'),
    clientdata:wx.getStorageSync('clientdata'),
    deviceName:wx.getStorageSync('devicedata').Name,
    SN:'1162134491',
    fr2ssid:'UTT-HIPER_4544C3DB',
    fr2pwd:'',
    fr5ssid:'sundi123',
    fr5pwd:'123456789',
    deviceid:''

  }
})
